﻿/// <reference path="jquery-1.3.2-vsdoc2.js" />


(function($) {
    jQuery.fn.extend({
        VoteAjax: function(opts) {
            opts = jQuery.extend({
                SelectObj: "VoteSelect",
                Voteid: "#Voteid"
            }, opts || {});
            var _Vote = $(this);
            _Vote.bind("click", function(e) {

                var UpdateId = $(opts.Voteid).val();
                var str = "";

                $("[name='" + opts.SelectObj + "'][checked]").each(function() {
                    str += $(this).val() + ',';
                });
                if (str == "") {
                    alert("请至少选择一项进行投票");
                    return false;
                }

                $.ajax({
                    url: JsPath + "AjaxXml/UpdateVote.aspx",
                    type: 'POST',
                    data: 'id=' + UpdateId + '&Selects=' + escape(str),
                    dataType: "html",
                    beforeSend: function() {
                        $("#imgloading").css({ "display": "block" });
                        $("#imgloading").css({ "top": (e.pageY - 65) });
                        _Vote.attr("disabled", "disabled");
                    },
                    error: function(data) {

                    },
                    success: function(data) {
                        if (data == "-2") {
                            alert("同一IP每天只能投票一次");
                            return false;
                        }
                        else if (data == "-1") {
                            alert("投票失败!");
                            return false;
                        }
                        else {
                            alert("投票成功!");
                            return false;
                        }
                    },
                    complete: function(data, textStatus) {
                        $("#imgloading").css({ "display": "none" });
                        $("#imgloading").css({ "top": "430" });
                        _Vote.removeAttr("disabled");

                        $("[name='" + opts.SelectObj + "'][checked]").each(function() {
                            $(this).removeAttr("checked");
                        });




                    }
                });






            });



        }
    });
})(jQuery);

$(document).ready(function() {
    $("#VoteSee").bind("click", function() {

        var Voteid = $("#Voteid").val();
        window.open(JsPath + 'VoteShow_' + Voteid + '.Aspx', '_Voteblank');

    });
});
